#include "KeywordAurelio.h"
#include <list>
#include <map>
#include <fstream>
#include <iostream>
#include <sstream>


using namespace std;

KeywordAurelio::KeywordAurelio()
{
}

KeywordAurelio::~KeywordAurelio()
{
}

void KeywordAurelio::addNewKeywords(const list< pair<unsigned long long, unsigned long long> > & keywordList) {
	list< pair<unsigned long long, unsigned long long> >::const_iterator it;
	for (it = keywordList.begin(); it != keywordList.end(); it++) {
		if (keywordMap[it->second] == NULL) {
//			cout << "it->first1: " << it->first<< endl;
			RBNode * rootPointer = new RBNode(0);
			RBNode * root = new RBNode(it->first);

			rootPointer->setParent(root);
			keywordMap[it->second] = rootPointer;
		}
		else {
//			cout << "it->first2: " << it->first << endl;
			RBNode * node = new RBNode(it->first);
			keywordMap[it->second]->insertNode(node);
		}
	}
}

void KeywordAurelio::coutKeywordMap(unsigned int myNumber) {
	map<unsigned long long, RBNode *>::iterator mapIt;
	stringstream ss;
	ss << myNumber;
	string fileName = "/work/miniLinkMaps/miniLinkMap_" + ss.str() + ".txt";
	cout << "fileName: " << fileName << endl;
	ofstream file(fileName.c_str());
	for (mapIt = keywordMap.begin(); mapIt != keywordMap.end(); mapIt++) {
//		file << "Hash: " << mapIt->first << endl;
//		cout << "Ocorrencias: ";
//		mapIt->second->showTree();
//		cout << endl;
		string myString = "";
		uint numOc = mapIt->second->setTreeString(myString);
		file << mapIt->first << ":" << numOc << ":" << myString << endl;
	}
}
